using System.Web.Mvc;
using Unity.Mvc3;
using Biblioteca.Models;
using Biblioteca.Interfaces;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Biblioteca.Filters;

namespace Biblioteca
{
    public static class Bootstrapper
    {
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers
            
            // e.g. container.RegisterType<ITestService, TestService>();            
            container.RegisterType<IAutor, AutorModel>();
            container.RegisterType<IEditorial, EditorialModel>();
            container.RegisterType<ITema,TemaModel>();
            container.RegisterType<ITipoUsuario, TipoUsuarioModel>();
            container.RegisterType<IEstadoReserva, EstadoReservaModel>();
            container.RegisterType<IUsuario, UsuarioModel>();
            container.RegisterType<IReserva, ReservasModel>();
            container.RegisterType<IMaterial, MaterialModel>();
            container.RegisterType<IPrestamo, PrestamoModel>();
            container.RegisterType<IEjemplar, EjemplarModel>();

            container.RegisterType<BibliotecaStore>(new HierarchicalLifetimeManager());

            /*Interception para la implementacion de crosscutting concern*/
            container.RegisterType<ICuentaUsuario, CuentaUsuarioModel>(
                new Interceptor<InterfaceInterceptor>(),
                new InterceptionBehavior<LoggingInterceptionBehavior>()
                );
            
            container.AddNewExtension<Interception>()
            .Configure<Interception>()
            .SetDefaultInterceptorFor<IMaterial>(new TransparentProxyInterceptor());



                    
            return container;
        }
    }
}